package com.ehome.poct.terminal.service;

import cn.hutool.core.util.StrUtil;
import com.ehome.core.page.PageInfo;
import com.ehome.exception.BizException;
import com.ehome.poct.base.api.constant.BizCode;
import com.ehome.poct.core.api.constant.enums.CheckOrderStatus;
import com.ehome.poct.core.api.dto.DelReportDTO;
import com.ehome.poct.core.api.dto.ReportListDTO;
import com.ehome.poct.core.api.dto.check.ReportDTO;
import com.ehome.poct.core.api.dto.report.*;
import com.ehome.poct.core.api.feign.OrderClient;
import com.ehome.poct.core.api.qry.OrderQry;
import com.ehome.poct.core.api.vo.CheckReportPageVO;
import com.ehome.poct.core.api.vo.ReportDetailVO;
import com.ehome.poct.core.api.vo.order.TestOrderVO;
import com.ehome.poct.core.api.vo.report.TestReportConfRecordVO;
import com.ehome.poct.core.api.vo.report.TestReportConfVO;

import java.util.List;
import java.util.Objects;

/**
 * @description:
 * @author: muqiu
 * @time: 2022/3/22 14:40
 */
public interface ReportService {
    /**
     * 报告列表
     *
     * @param dto
     * @return
     */
    CheckReportPageVO list(ReportListDTO dto);

    /**
     * 删除检测报告
     *
     * @param delReportDTO
     */
    void deleteById(DelReportDTO delReportDTO);

    /**
     * 根据订单号打印数据
     *
     * @param orderNo
     * @param local
     * @return
     */
    ReportDetailVO getOneByOrderNoPrint(String orderNo, Boolean local);

    /**
     * 告知打印机状态
     *
     * @param clinicId
     * @param status
     */
    void toSendStatus(Long clinicId, String status);

    void createReport(ReportReqDTO reportReqDTO);

    List<ReportDTO> getSummary(String orderNo);

    void reportConf(ReportConfigDTO reportConfigDTO);

    PageInfo<TestReportConfVO> reportConfPage(ReportConfigQry reportConfigQry);

    PageInfo<TestReportConfRecordVO> reportConfRecord(ReportConfigRecordDTO reportConfigRecordDTO);

    ClinicInfoVO clinicInfo(String account);

    default void checkOrderStatus(String orderNo, OrderClient orderClient) {
        if (StrUtil.isBlank(orderNo)) {
            throw new BizException(BizCode.NOT_FOUND_TEST_ORDER.getBusiCode(), "orderNo不能为空");
        }
        TestOrderVO testOrderVO = orderClient.getOne(new OrderQry().setTestOrderNo(orderNo));
        if (Objects.isNull(testOrderVO)) {
            throw new BizException(BizCode.NOT_FOUND_TEST_ORDER.getBusiCode(), String.format(BizCode.NOT_FOUND_TEST_ORDER.getMsg(), orderNo));
        }

        if (CheckOrderStatus.REFUND_SUCCESS.getCode().equals(testOrderVO.getStatus())) {
            throw new BizException(BizCode.TEST_ORDER_REFUND);
        }
    }
}
